﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DAO;

namespace TAM_SPORT
{
    public partial class SaleReport : TAM_SPORT.FormBase
    {
        private SalesDao sdao;
        public SaleReport()
        {
            InitializeComponent();
            sdao = new SalesDao();
            loadGrid();
        }
        private void loadGrid()
        {
            DataTable table = sdao.getSales(dtFrom.Value, dtTo.Value);
            double allTotal = 0;
            double debit = 0;
            double realTotal = 0;
            dtgCustomers.Rows.Clear();
            if (table != null && table.Rows.Count > 0)
            {
                foreach (DataRow row1 in table.Rows)
                {
                    allTotal += Convert.ToDouble(row1["TOTAL"]);
                    debit += Convert.ToDouble(row1["DEBIT_MONEY"]);
                    realTotal += Convert.ToDouble(row1["PAY_MONEY"]);
                    int i = dtgCustomers.Rows.Add();
                    dtgCustomers.Rows[i].Cells[0].Value = i + 1;
                    dtgCustomers.Rows[i].Cells[1].Value = row1["CUSTOMER_NAME"].ToString();
                    dtgCustomers.Rows[i].Cells[2].Value = row1["PRODUCT_NAME"].ToString();
                    dtgCustomers.Rows[i].Cells[3].Value = row1["UNIT_NAME"].ToString();
                    dtgCustomers.Rows[i].Cells[4].Value = Convert.ToDouble(row1["SO_LUONG"]).ToString("#,###.##");
                    dtgCustomers.Rows[i].Cells[5].Value = Convert.ToDouble(row1["TOTAL"]).ToString("#,###.##");
                    dtgCustomers.Rows[i].Cells[6].Value = Convert.ToDouble(row1["PAY_MONEY"]).ToString("#,###.##");
                    dtgCustomers.Rows[i].Cells[7].Value = Convert.ToDouble(row1["DEBIT_MONEY"]).ToString("#,###.##");
                    dtgCustomers.Rows[i].Cells[8].Value = row1["ID"].ToString();
                    if (i % 2 == 1)
                    {
                        dtgCustomers.Rows[i].DefaultCellStyle.BackColor = Color.LightCyan;
                    }
                }
            }
            txtAlltotal.Text = allTotal.ToString("#,###.##");
            txtDebit.Text = debit.ToString("#,###.##");
            txtReadTotal.Text = realTotal.ToString("#,###.##");
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            loadGrid();
        }
    }
}
